package com.spic.business.plan.book.controller;

import com.spic.business.plan.book.domain.PlanStandingBook;
import com.spic.business.plan.book.service.IPlanStandingBookService;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import com.spic.system.api.RemoteUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 应急预案台账Controller
 *
 * @author spic
 * @date 2021-10-28
 */
@RestController
@RequestMapping("plan/book")
public class PlanStandingBookController extends BaseController
{
    @Autowired
    private IPlanStandingBookService planStandingBookService;

    /**
     * 查询应急预案台账列表
     */
    @PreAuthorize(hasPermi = "business/plan:book:list")
    @GetMapping("/list")
    public TableDataInfo list(PlanStandingBook planStandingBook)
    {
        startPage();
        List<PlanStandingBook> list = planStandingBookService.selectPlanStandingBookList(planStandingBook);
        return getDataTable(list);
    }

    /**
     * 导出应急预案台账列表
     */
    @PreAuthorize(hasPermi = "business/plan:book:export")
    @Log(title = "应急预案台账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlanStandingBook planStandingBook) throws IOException
    {
        List<PlanStandingBook> list = planStandingBookService.selectPlanStandingBookList(planStandingBook);
        ExcelUtil<PlanStandingBook> util = new ExcelUtil<PlanStandingBook>(PlanStandingBook.class);
        util.exportExcel(response, list, "应急预案台账数据");
    }

    /**
     * 获取应急预案台账详细信息
     */
    @PreAuthorize(hasPermi = "business/plan:book:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(planStandingBookService.selectPlanStandingBookById(id));
    }

    /**
     * 新增应急预案台账
     */
    @PreAuthorize(hasPermi = "business/plan:book:add")
    @Log(title = "应急预案台账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PlanStandingBook planStandingBook)
    {
        return toAjax(planStandingBookService.insertPlanStandingBook(planStandingBook));
    }

    /**
     * 修改应急预案台账
     */
    @PreAuthorize(hasPermi = "business/plan:book:edit")
    @Log(title = "应急预案台账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlanStandingBook planStandingBook)
    {
        return toAjax(planStandingBookService.updatePlanStandingBook(planStandingBook));
    }

    /**
     * 删除应急预案台账
     */
    @PreAuthorize(hasPermi = "business/plan:book:remove")
    @Log(title = "应急预案台账", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(planStandingBookService.deletePlanStandingBookByIds(ids));
    }
}
